﻿// Decompiled with JetBrains decompiler
// Type: MCM.Implementation.FluentBuilder.DefaultSettingsPropertyGroupBuilder
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using MCM.Abstractions;
using MCM.Abstractions.FluentBuilder;
using MCM.Abstractions.FluentBuilder.Models;
using MCM.Abstractions.Wrapper;
using MCM.Common;
using MCM.Implementation.FluentBuilder.Models;
using System;
using System.Collections.Generic;

#nullable enable
namespace MCM.Implementation.FluentBuilder
{
  internal sealed class DefaultSettingsPropertyGroupBuilder : 
    ISettingsPropertyGroupBuilder,
    IPropertyGroupDefinition
  {
    public Dictionary<string, ISettingsPropertyBuilder> Properties { get; } = new Dictionary<string, ISettingsPropertyBuilder>();

    public string GroupName { get; }

    public int GroupOrder { get; private set; }

    private bool HasGroupToggle { get; set; }

    public DefaultSettingsPropertyGroupBuilder(string name) => this.GroupName = name;

    public ISettingsPropertyGroupBuilder SetGroupOrder(int value)
    {
      this.GroupOrder = value;
      return (ISettingsPropertyGroupBuilder) this;
    }

    public ISettingsPropertyGroupBuilder AddToggle(
      string id,
      string name,
      IRef @ref,
      Action<ISettingsPropertyGroupToggleBuilder>? builder)
    {
      this.HasGroupToggle = !this.HasGroupToggle ? true : throw new InvalidOperationException("There already exists a group toggle property!");
      if (!this.Properties.ContainsKey(name))
        this.Properties[name] = (ISettingsPropertyBuilder) new DefaultSettingsPropertyGroupToggleBuilder(id, name, @ref);
      if (builder != null)
        builder((ISettingsPropertyGroupToggleBuilder) this.Properties[name]);
      return (ISettingsPropertyGroupBuilder) this;
    }

    public ISettingsPropertyGroupBuilder AddBool(
      string id,
      string name,
      IRef @ref,
      Action<ISettingsPropertyBoolBuilder>? builder)
    {
      if (!this.Properties.ContainsKey(name))
        this.Properties[name] = (ISettingsPropertyBuilder) new DefaultSettingsPropertyBoolBuilder(id, name, @ref);
      if (builder != null)
        builder((ISettingsPropertyBoolBuilder) this.Properties[name]);
      return (ISettingsPropertyGroupBuilder) this;
    }

    public ISettingsPropertyGroupBuilder AddDropdown(
      string id,
      string name,
      int selectedIndex,
      IRef @ref,
      Action<ISettingsPropertyDropdownBuilder>? builder)
    {
      if (!this.Properties.ContainsKey(name))
        this.Properties[name] = (ISettingsPropertyBuilder) new DefaultSettingsPropertyDropdownBuilder(id, name, selectedIndex, @ref);
      if (builder != null)
        builder((ISettingsPropertyDropdownBuilder) this.Properties[name]);
      return (ISettingsPropertyGroupBuilder) this;
    }

    public ISettingsPropertyGroupBuilder AddInteger(
      string id,
      string name,
      int minValue,
      int maxValue,
      IRef @ref,
      Action<ISettingsPropertyIntegerBuilder>? builder)
    {
      if (!this.Properties.ContainsKey(name))
        this.Properties[name] = (ISettingsPropertyBuilder) new DefaultSettingsPropertyIntegerBuilder(id, name, minValue, maxValue, @ref);
      if (builder != null)
        builder((ISettingsPropertyIntegerBuilder) this.Properties[name]);
      return (ISettingsPropertyGroupBuilder) this;
    }

    public ISettingsPropertyGroupBuilder AddFloatingInteger(
      string id,
      string name,
      float minValue,
      float maxValue,
      IRef @ref,
      Action<ISettingsPropertyFloatingIntegerBuilder>? builder)
    {
      if (!this.Properties.ContainsKey(name))
        this.Properties[name] = (ISettingsPropertyBuilder) new DefaultSettingsPropertyFloatingIntegerBuilder(id, name, minValue, maxValue, @ref);
      if (builder != null)
        builder((ISettingsPropertyFloatingIntegerBuilder) this.Properties[name]);
      return (ISettingsPropertyGroupBuilder) this;
    }

    public ISettingsPropertyGroupBuilder AddText(
      string id,
      string name,
      IRef @ref,
      Action<ISettingsPropertyTextBuilder>? builder)
    {
      if (!this.Properties.ContainsKey(name))
        this.Properties[name] = (ISettingsPropertyBuilder) new DefaultSettingsPropertyTextBuilder(id, name, @ref);
      if (builder != null)
        builder((ISettingsPropertyTextBuilder) this.Properties[name]);
      return (ISettingsPropertyGroupBuilder) this;
    }

    public ISettingsPropertyGroupBuilder AddButton(
      string id,
      string name,
      IRef @ref,
      string content,
      Action<ISettingsPropertyButtonBuilder>? builder)
    {
      if (!this.Properties.ContainsKey(name))
        this.Properties[name] = (ISettingsPropertyBuilder) new DefaultSettingsPropertyButtonBuilder(id, name, @ref, content);
      if (builder != null)
        builder((ISettingsPropertyButtonBuilder) this.Properties[name]);
      return (ISettingsPropertyGroupBuilder) this;
    }

    public ISettingsPropertyGroupBuilder AddCustom<TSettingsPropertyBuilder>(
      ISettingsPropertyBuilder<TSettingsPropertyBuilder> builder)
      where TSettingsPropertyBuilder : ISettingsPropertyBuilder
    {
      if (!this.Properties.ContainsKey(builder.Name))
        this.Properties[builder.Name] = (ISettingsPropertyBuilder) builder;
      return (ISettingsPropertyGroupBuilder) this;
    }

    public IPropertyGroupDefinition GetPropertyGroupDefinition()
    {
      return (IPropertyGroupDefinition) new PropertyGroupDefinitionWrapper((object) this);
    }
  }
}
